package com.taplinker.client.im.activity.message;

import com.taplinker.client.R;
import com.taplinker.client.im.domain.EnumMessageType;
import com.taplinker.client.im.protocol.TapLinkerMessage;

public enum MessageTypeEnum {
	LEFT_TEXT(EnumMessageType.TEXT.getType(), 0, true,
			R.layout.chat_list_left_textitem), RIGHT_TEXT(EnumMessageType.TEXT
			.getType(), 1, false, R.layout.chat_list_right_textitem), LEFT_IMAGE(
			EnumMessageType.IMAGE.getType(), 2, true,
			R.layout.chat_list_left_imageitem), RIGHT_IMAGE(
			EnumMessageType.IMAGE.getType(), 3, false,
			R.layout.chat_list_right_imageitem), LEFT_AUDIO(
			EnumMessageType.AUDIO.getType(), 4, true,
			R.layout.chat_list_left_audioitem), RIGHT_AUDIO(
			EnumMessageType.AUDIO.getType(), 5, false,
			R.layout.chat_list_right_audioitem);

	private String typeText;
	private int typeNo;
	private int layoutId;
	private boolean isLeft;

	MessageTypeEnum(String typeText, int typeNo, boolean isLeft, int layoutId) {
		this.typeText = typeText;
		this.typeNo = typeNo;
		this.layoutId = layoutId;
	}

	public String getTypeText() {
		return typeText;
	}

	public int getTypeNo() {
		return typeNo;
	}

	public int getLayoutId() {
		return layoutId;
	}

	public boolean isLeft() {
		return isLeft;
	}

	public static MessageTypeEnum getTypeByNo(int typeNo) {
		switch (typeNo) {
		case 0:
			return LEFT_TEXT;
		case 1:
			return RIGHT_TEXT;
		case 2:
			return LEFT_IMAGE;
		case 3:
			return RIGHT_IMAGE;
		case 4:
			return LEFT_AUDIO;
		case 5:
			return RIGHT_AUDIO;

		default:
			return RIGHT_TEXT;
		}
	}

	public static MessageTypeEnum getMessageType(TapLinkerMessage message) {
		if (message.getSendUserId() < 1) {
			if (message.getType().equalsIgnoreCase(
					EnumMessageType.TEXT.getType()))
				return LEFT_TEXT;
			if (message.getType().equalsIgnoreCase(
					EnumMessageType.IMAGE.getType()))
				return LEFT_IMAGE;
			if (message.getType().equalsIgnoreCase(
					EnumMessageType.AUDIO.getType()))
				return LEFT_AUDIO;

		} else {
			if (message.getType().equalsIgnoreCase(
					EnumMessageType.TEXT.getType()))
				return RIGHT_TEXT;
			if (message.getType().equalsIgnoreCase(
					EnumMessageType.IMAGE.getType()))
				return RIGHT_IMAGE;
			if (message.getType().equalsIgnoreCase(
					EnumMessageType.AUDIO.getType()))
				return RIGHT_AUDIO;

		}
		return LEFT_TEXT;
	}

}
